
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>

#define NLOOP   5000

int counter = 0;

void * doit(void *);

// build : gcc -Wall -g example01.c -o example01 -lpthread
int main(int argc, char * argv[]) {

    pthread_t   tidA, tidB;

    pthread_create(&tidA, NULL,doit, NULL);
    pthread_create(&tidB, NULL,doit, NULL);

    pthread_join(tidA, NULL);
    pthread_join(tidB, NULL);
    return EXIT_SUCCESS;
}

void * doit(void * ptr) {

    int i,  value;

    for (i = 0; i < NLOOP; i++) {

        value = counter;
        printf("%ld: %d\n", pthread_self(), value + 1);

        counter = value + 1;
    }
    return(NULL);
}